import {Component} from '@angular/core';
import {GnTableButton, GnTableComponent} from 'geminis-ng';

@Component({
  selector: 'everydata-form-editor-item-table-button',
  template: `
    <a nz-button (click)="addData()" [disabled]="table.editData !== null">
      <i nz-icon nzIconfont="plus"></i>
    </a>
    <a nz-button (click)="table.deleteSelectedData()" [disabled]="!table.isSelected">
      <i nz-icon nzIconfont="minus"></i>
    </a>
    <a nz-button (click)="table.startEdit(table.selectedOne)" [disabled]="table.editData !== null || !table.isSingleSelected">
      <i nz-icon nzIconfont="edit"></i>
    </a>
    <a nz-button (click)="table.endEdit()" [disabled]="table.editData === null">
      <i nz-icon nzIconfont="check"></i>
    </a>
  `
})
@GnTableButton('FormEditorItemTableButton')
export class FormEditorItemTableButtonComponent {

  table!: GnTableComponent;

  addData(): void {
    if (!this.table.data) {
      this.table.data = [];
    }
    this.table.data.push({label: '显示内容', value: '值内容'});
    this.table.refreshData(this.table.data);
    this.table.dataSaved.emit(null);
  }

}
